//
//  UIBarButtonItem+Extension.swift
//  NBSinaWeibo
//
//  Created by ac on 16/5/19.
//  Copyright © 2016年 ac. All rights reserved.
//

import UIKit

extension UIBarButtonItem{
    convenience init(imageName: String? = nil,title: String? = nil,target: AnyObject?, action: Selector) {
        self.init()
        
        let btn = UIButton()
        if let img = imageName {
            btn.setImage(UIImage(named: img), forState: .Normal)
            btn.setImage(UIImage(named: img + "_highlighted"), forState: .Highlighted)
        }
        
        
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        btn.sizeToFit()
        
        self.customView = btn
        
    }
    
//    func init(imageName: String,title: String? = nil,target: AnyObject?, action: Selector,name: String) {
//        
//    }
}